<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div>
        <span>订单号：</span>
        <input type="text" id="order">
    </div>
    <button id="btn">生成订单</button>
    <script>
        var btn = document.getElementById("btn");
        var order = document.getElementById("order")
        btn.onclick = function() {
            getDateNow();
        }

        function getDateNow() {
            var time = new Date();
            var year = String(time.getFullYear());
            var month = String(time.getMonth() + 1);
            var day = String(time.getDate());
            var hours = String(time.getHours());
            if (hours.length < 2) {
                hours = "0" + hours;
            }
            var minutes = String(time.getMinutes());
            if (minutes.length < 2) {
                minutes = "0" + minutes;
            }
            var seconds = String(time.getSeconds());
            if (seconds.length < 2) {
                seconds = "0" + seconds;
            }
            var str = year + month + day + hours + minutes + seconds;
            order.value = str;
            console.log(year, month, day, hours, minutes, seconds, str);
        }
    </script>
</body>

</html>